<template>
  <div class="reportbox" v-bind:class="{owidth:pushStatus}">
    <div v-if="!pushStatus">
     <h4 style="margin:0 0 10px 0"> 
      <span>预约管理</span>
    </h4>
   
    <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
      <!--<el-table-column type="selection" width="55"></el-table-column>-->
      <el-table-column prop="ID" label="序号" width="60">
         <template slot-scope="scope">{{scope.$index+1}}</template>
      </el-table-column>
     <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="tel" label="手机"></el-table-column>
      <el-table-column prop="applicant_id" label="id"></el-table-column>
      <el-table-column prop="time" label="预约时间" width="200">
        <template slot-scope="scope">
          {{timeFun(scope.row.time)}}
        </template>
      </el-table-column>
      <el-table-column prop="age" label="年龄">
        <!-- <template slot-scope="scope">
          {{ageFun(scope.row.age)}}
        </template> -->
      </el-table-column>
      <el-table-column prop="server_tag" label="商品名"></el-table-column>
      <el-table-column prop="type" label="类别">
        <template  slot-scope="scope">
          <span style="color:#67c23a" v-if="scope.row.type==1">商家预约</span>
          <span v-else-if="scope.row.type==2">活动预约</span>
          <span v-else>商品预约</span>
        </template>
      </el-table-column>
      <el-table-column prop="remark" label="备注"></el-table-column>
      <el-table-column prop="status" label="状态">
        <template  slot-scope="scope">
          <span  v-if="scope.row.status==0">未到店</span>
          <span v-else-if="scope.row.status==1" style="color:#67c23a" >已到店</span>
          <span v-else-if="scope.row.status==2" style="color:red" >取消预约</span>
          <span v-else>已过期</span>
        </template>
      </el-table-column>
      <el-table-column width="100" label="操作">
        <template slot-scope="scope">
          <div>
            <!-- <el-button class="addBtn" type="primary" @click="seachFun(scope.row)">查看</el-button> -->
            <el-button class="addBtn" v-if="scope.row.status==0" type="primary" @click="seachFun(scope.row.id)">到店</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    </div>
     <div v-if="pushStatus">
       <Addreport  @getlist = "getlist" ref="artice" :editData="editData"></Addreport>
    </div>

  </div>
</template>

<script>
  import Addreport from './Pushitem/Addreport'
  import Http from '@/Http/Http'
  import getTime from '@/Http/getTime'
  export default {
    data() {
      return {
        pushStatus:false,
        value:'关注',
        editData:'',
        total:0,
        currentPage4: 1,//分野  
        page:1,
        pageSize:10,
        tableData: []
      }
    },
    components:{
      Addreport
    },
    created(){
      this.getlist()
    },
    methods: {
      getlist(){
        Http.getReserveList({
          "pageIndex":this.page,
          "pageSize":this.pageSize
        })
        .then( res => {
          this.tableData = res.data.data.rows
          console.log(res.data.data)
        })
        this.pushStatus = false
      },
       getdata (evt) {
            console.log(evt.draggedContext.element.text)
        },
        datadragEnd (evt) {
            evt.preventDefault();
            console.log('拖动前的索引 :' + evt.oldIndex)
            console.log('拖动后的索引 :' + evt.newIndex)
            console.log(this.colors);
        },
      timeFun(val) {
        return getTime(val)
      },
      ageFun(val) {
        const newo = new Date();
        const newYear = newo.getFullYear();
        const now =  new Date(val)
        const year = now.getFullYear();
        return newYear - year
        console.log(newYear,year)
      },
      //添加用户
      seachFun(id) {
        // 原来需要医生确认 就诊
        // this.editData = row;
        // this.pushStatus = true

        this.$confirm(`确认到店？`)
        .then(_ => {
          
          Http.goHome({"id":id})
          .then( res => {
            if (res.data.code == 200) {
              this.$message.success('到店成功')
              this.getlist()
            } else if(res.data.code == -1003) {
              this.$message.error(`请求失败原因：${res.data.message}`)
            } else {
              this.$message.error('到店失败')}
          })
          .catch( error => {
            console.log(error)
            this.$message.error('服务器请求失败')
          })
        })
        .catch(_ => {
          //取消部分
          console.log('bb')
        });

      },
      
      //选择 推荐
      handleSelectionChange() {
        
      },
       //分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.getlist()
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val;
        this.getlist()
        console.log(`当前页: ${val}`);
      },
    }
  }
</script>
<style  scoped>
.reportbox{
  background: #fff;
  padding:10px;
  min-height: 500px
}
.owidth{
  width: 80%
}
</style>
